from math import pi


def _1():
    cel = eval(input('Enter a degree in celsius:'))
    print(cel, 'Celsius is', (9 / 5) * cel + 32, 'Fahrenheit')
    return 0


def _2():
    radius, length = eval(input('Enter the radius and length of a cylinder:'))
    print('The area is', radius * radius * pi, '\nThe volume is', radius * radius * pi * length)
    return 0


def _3():
    feet = eval(input('Enter a value for feet:'))
    print(feet, 'feet is', feet * 0.305, 'meters')
    return 0


def _4():
    pound = eval(input('Enter a value in pound:'))
    print(pound, 'pound is', pound * 0.454, 'kilograms')
    return 0


def _5():
    subtotal, gra_rate = eval(input('Enter the subtotal and a gratuity rate:'))
    print('The gratuity is', format((subtotal * gra_rate * 0.01), '.2f'), 'and the total is',
          format((subtotal + subtotal * gra_rate * 0.01), '.2f'))
    return 0


def _6():
    the_num = eval(input("Enter a number between 0 and 1000:"))
    total = 0
    while (the_num % 10) != 0:
        total += the_num % 10
        the_num = the_num // 10
    print("The sum of the digits is", total)
    return 0


def _7():
    minutes = eval(input("Enter the number of minutes:"))
    print(minutes, "minutes is approximately", int((minutes / (60 * 24 * 365)) // 1), "years and",
          int(((minutes % (60 * 24 * 365)) / (60 * 24)) // 1), "days")
    return 0


def _8():
    water_amount = eval(input("Enter the amount of water in kilograms:"))
    init_tem = eval(input("Enter the initial temperature:"))
    fin_tem = eval(input("Enter the final temperature:"))
    print("The energy needed is", water_amount * (fin_tem - init_tem) * 4184)
    return 0


def _9():
    temperature = eval(input("Enter the temperature in Fahrenheit between -58 and 41:"))
    wind_speed = eval(input("Enter the wind speed in miles per hour:"))
    print("THe wind chill index is", format((35.74 + 0.6215 * temperature - 35.74 * pow(wind_speed,
                                                                                        0.16) + 0.4275 * temperature * pow(
        wind_speed, 0.16)), '.5f'))
    return 0


def _10():
    speed, acceleration = eval(input("Enter speed and acceleration:"))
    print("The minimum runway length for this airplane is",format((speed**2)/(2*acceleration),'.3f'),"meters")
    return 0


def _11():
    final_value = eval(input("Enter final account value:"))
    annual_int_rate = eval(input("Enter annual interest rate in percent:"))
    years = eval(input("Enter number of years:"))
    print("Initial deposit value is",final_value/pow((1+(annual_int_rate*0.01)/12),(years*12)))
    return 0


def _12():
    i = 1;
    print("a\t b\t a ** b\t")
    while i < 6:
        print(i, "\t", i + 1, "\t", pow(i, i + 1), "\t")
        i += 1
    return 0


def _13():
    num = input("Enter an integer:")
    lst = list(num)
    lst.reverse()
    for i in range(0, len(lst)):
        print(lst[i])
    return 0


def _14():
    x_1, y_1, x_2, y_2, x_3, y_3 = eval(input("Enter three points for a triangle:"))
    side_1 = ((x_1 - x_2) ** 2 + (y_1 - y_2) ** 2) ** (1 / 2)
    side_2 = ((x_3 - x_2) ** 2 + (y_3 - y_2) ** 2) ** (1 / 2)
    side_3 = ((x_1 - x_3) ** 2 + (y_1 - y_3) ** 2) ** (1 / 2)
    semi_perimeter = (side_1 + side_2 + side_3) / 2
    area = (semi_perimeter * (semi_perimeter - side_1) * (semi_perimeter - side_2) * (semi_perimeter - side_3)) ** (
            1 / 2)
    print("The area of the triangle is", format(area, '.1f'))


def _15():
    side = eval(input("Enter the side:"))
    print("The area of the hexagon is", format(((3 * 3 ** (1 / 2)) / 2) * side * side, '.4f'))
    return 0


def _16():
    v_0, v_1, t = eval(input("Enter v0, v1, and t:"))
    print("The average acceleration is", format((v_1 - v_0) / t, '.4f'))
    return 0


def _17():
    weight = eval(input("Enter weight in pounds:"))
    height = eval(input("Enter height in inches:"))
    print("BMI is", format((weight * 0.45359237) / ((height * 0.0254) ** 2), '.4f'))


def _18():  # 这道题因为程序清单2-7的程序没有考虑闰秒，所以差距有点大
    current_time = time.time()
    total_seconds = int(current_time)
    current_seconds = total_seconds % 60
    total_minutes = total_seconds // 60
    current_minute = total_minutes % 60
    total_hours = total_minutes // 60
    current_hour = total_hours % 24
    offset = eval(input("Enter the time zone offset to GMT:"))
    print("The current time is", current_hour + offset, ':', current_minute, ':', current_seconds)


def _19():
    invest_amount = eval(input("Enter investment amount:"))
    annual_int_rate = eval(input("Enter annual interest rate:"))
    year = eval(input("Enter number of years:"))
    print("Accumulated value is", format((invest_amount * (1 + (annual_int_rate*0.01) / 12) ** (year * 12)), '.2f'))
    return 0


def _20():
    balance, int_rate = eval(input("Enter balance and interest rate"))
    print("The interest is",balance*((int_rate*0.01)/1200))


def _21():
    save_amount = eval(input("Enter the monthly saving amount:"))
    while i < 7:
        if i == 1:
            total_amount = save_amount * (1 + 0.00417)
        else:
            total_amount = (save_amount + total_amount) * (1 + 0.00417)
        i += 1
    print("After the sixth month, the account value is",total_amount)


def _22():
    year = eval(input("Enter the number of years:"))
    number = 3120324986
    for i in range(1, year):
        number = number + (365 * 24 * 60 * 60 // 7) - (365 * 24 * 60 * 60 // 13) + (365 * 24 * 60 * 60 // 45)
    print("The population in", year, "is", number)


def main():
    num = eval(input("Input number to show answer:"))
    if num == 1:
        _1()
    elif num == 2:
        _2()
    elif num == 3:
        _3()
    elif num == 4:
        _4()
    elif num == 5:
        _5()
    elif num == 6:
        _6()
    elif num == 7:
        _7()
    elif num == 8:
        _8()
    elif num == 9:
        _9()
    elif num == 10:
        _10()
    elif num == 11:
        _11()
    elif num == 12:
        _12()
    elif num == 13:
        _13()
    elif num == 14:
        _14()
    elif num == 15:
        _15()
    elif num == 16:
        _16()
    elif num == 17:
        _17()
    elif num == 18:
        _18()
    elif num == 19:
        _19()
    elif num == 20:
        _20()
    elif num == 21:
        _21()
    elif num ==22:
        _22()

        
main()



